package com.fsc.entity;

import com.fsc._enum.ReturnEnum;
import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * 返回结果包装类,分成功、客户端失败以及服务器错误三大类
 * @param <T>
 */
@Data
public class ResultWrapper<T> {
    private int code;
    private String message;
    private T data;

    public static <T> ResultWrapper<T> success(ReturnEnum returnEnum, T data) {
        ResultWrapper<T> result = new ResultWrapper<>();
        result.setCode(returnEnum.getCode());
        result.setMessage(returnEnum.getMessage());
        result.setData(data);
        return result;
    }
    public static <T> ResultWrapper<T> success(String message) {
        ResultWrapper<T> result = new ResultWrapper<>();
        result.setCode(ReturnEnum.SUCCESS.getCode());
        result.setMessage(message);
        result.setData(null);
        return result;
    }
    public static <T> ResultWrapper<T> success(ReturnEnum returnEnum) {
        ResultWrapper<T> result = new ResultWrapper<>();
        result.setCode(returnEnum.getCode());
        result.setMessage(returnEnum.getMessage());
        result.setData(null);
        return result;
    }

    public static <T> ResultWrapper<T> fail(ReturnEnum returnEnum, T data) {
        ResultWrapper<T> result = new ResultWrapper<>();
        result.setCode(returnEnum.getCode());
        result.setMessage(returnEnum.getMessage());
        result.setData(data);
        return result;
    }
    public static <T> ResultWrapper<T> fail(ReturnEnum returnEnum) {
        ResultWrapper<T> result = new ResultWrapper<>();
        result.setCode(returnEnum.getCode());
        result.setMessage(returnEnum.getMessage());
        result.setData(null);
        return result;
    }

    public static <T> ResultWrapper<T> error() {
        ResultWrapper<T> result = new ResultWrapper<>();
        result.setCode(ReturnEnum.SYSTEM_ERROR.getCode());
        result.setMessage(ReturnEnum.SYSTEM_ERROR.getMessage());
        return result;
    }
    public static <T> ResultWrapper<T> error(String message) {
        ResultWrapper<T> result = new ResultWrapper<>();
        result.setCode(ReturnEnum.SYSTEM_ERROR.getCode());
        result.setMessage(message);
        return result;
    }
}
